<?php

namespace app\admin\model;

use think\Model;

class UsersCate extends Model
{
    /**
     * 身份数据
     * @param $where
     * @return mixed
     */
    public static function findUsersIdentity($where)
    {
        return self::alias('u')
            ->join('identity i', 'i.id = u.identity_id', 'left')
            ->where($where)
            ->value('i.name');
    }

    /**
     * 所有身份数据
     * @return array
     */
    public static function getUsersIdentity()
    {
        $data = self::fieldRaw('COUNT(*) as nums,i.name')
            ->alias('u')
            ->join('identity i', 'i.id = u.identity_id', 'left')
            ->group('i.name')
            ->order('nums', 'desc')
            ->select();

        return $data ? $data->toArray() : [];
    }
}